from django.shortcuts import render

# Create your views here.
from rest_framework.views import APIView

from AKapi.settings.const import *
from AKapi.utils.response import APIResponse
from rest_framework.response import Response
from rest_framework.mixins import ListModelMixin
from rest_framework.generics import GenericAPIView
from rest_framework.viewsets import GenericViewSet


# class TestView(APIView):
#     def get(self, *args, **kwargs):
#         print(kwargs)
#         dic = {'name': 'AK'}
#         print('get.....')
#         # print(dic['age'])
#         return APIResponse()
#
#     def options(self, request, *args, **kwargs):
#         print('options....')
#         return APIResponse()
#
#     def post(self, *args, **kwargs):
#         print(kwargs)
#         dic = {'name': 'AK'}
#         print('post....')
#         # print(dic['age'])
#         # return APIResponse(headers={'Access-Control-Allow-Origin': 'http://127.0.0.1:8002', 'Access-Control-Allow-Headers': 'Content-Type'})
#         return APIResponse()
from home import models, serializer


# class BannerView(GenericAPIView, ListModelMixin):  # 路由配置 path('banner/', views.BannerView.as_view()),
# class BannerView(GenericViewSet, ListModelMixin):
# 路由配置用drf路由
class BannerView(GenericViewSet, ListModelMixin):
    # 无论后边有多少数据要展示，只展示3条
    queryset = models.Banner.objects.filter(is_delete=False, is_show=True).order_by('display_order')[:BANNER_COUNTER]
    serializer_class = serializer.BannerModelSerializer